package com.ljh.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ljh.pojo.Collection;
import io.swagger.models.auth.In;
import org.apache.ibatis.annotations.*;

import java.nio.channels.Pipe;
import java.util.Date;
import java.util.List;

@Mapper
public interface CollectionMapper extends BaseMapper<Collection> {

    /**
     * 通过随机函数取9个
     * @return
     */
    @Select("select * from collection order by rand() limit 9")
    public List<Collection> findAllColl();

    /**
     * 通过专辑Id来查询专辑
     * @param id
     * @return
     */
    @Select("select * from collection where collId = #{id}")
    public Collection findCollById(Integer id);

    /**
     * 通过id来查找专辑
     * @param userId
     * @return
     */
    @Select("select * from collection where collsinger = #{userId}")
    public List<Collection> findCollByUserId(Integer userId);

    /**
     * 通过专辑作者删除
     * @param userId
     */
    @Delete("delete from collection where collsinger = #{userId}")
    public void deleteCollByUserId(Integer userId);

    /**
     * 通过专辑id来删除专辑
     * @param collId
     */
    @Delete("delete from collection where collId = #{collId}")
    public void deleteCollById(Integer collId);

    /**
     * 更新照片
     * @param collPhoto
     * @param collId
     */
    @Update("update collection set collPhoto = #{collPhoto} where collId = #{collId}")
    public void updateListPhoto(String collPhoto,Integer collId);

    @Insert("insert into collection (collName,collDate,collsinger,singerName) values (#{collName},#{collDate},#{singerId},#{singerName})")
    public void insertCollection(String collName, String collDate, Integer singerId, String singerName);

    @Insert("update collection set collName = #{collName},singerName = #{singerName},collDate = #{collDate} where collId = #{collId}")
    public void updateColl(String collName,String singerName,String collDate,Integer collId);
}
